function [comp_aud]=compress_aud_data(aud_data,shutter_channel)
% this function compresses the aud_data and subsamples sound energy at a
% sampling rate of 1kHz

cnt=0;
go_on=1;
shutter_close=1;
while go_on
    cnt=cnt+1;
    if isempty(find(shutter_channel(shutter_close(cnt):end)>2.5,1))
        go_on=0;
    else
        shutter_open(cnt)=find(shutter_channel(shutter_close(cnt):end)>2.5,1)+shutter_close(cnt);
        shutter_close(cnt+1)=find(shutter_channel(shutter_open(cnt):end)<2.5,1)+shutter_open(cnt);
    end
end


cnt=0;
go_on=1;
Ashutter_close=1;
while go_on
    cnt=cnt+1;
    if isempty(find(aud_data(1,Ashutter_close(cnt):end)>intmax('int16')/2,1))
        go_on=0;
    else
        Ashutter_open(cnt)=find(aud_data(1,Ashutter_close(cnt):end)>intmax('int16')/2,1)+Ashutter_close(cnt);
        Ashutter_close(cnt+1)=find(aud_data(1,Ashutter_open(cnt):end)<intmax('int16')/2,1)+Ashutter_open(cnt);
    end
end

comp_aud=nan(length(shutter_channel),1);

for ind=1:length(shutter_open)
    tmp=decimate(double(aud_data(2,Ashutter_open(ind):Ashutter_close(ind+1))).^2,32);
    comp_aud(shutter_open(ind):shutter_open(ind)+length(tmp)-1)=tmp;
end



